home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / include / Timer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-11-25  |  2.9 KB  |  124 lines

  1.  
  2. #ifndef __TIMER_H_
  3. #define __TIMER_H_
  4. /**
  5. Peon - Win32 Games Programming Library
  6. Copyright (C) 2002-2005 Erik Yuzwa
  7.  
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public
  10. License as published by the Free Software Foundation; either
  11. version 2 of the License, or (at your option) any later version.
  12.  
  13. This library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. Library General Public License for more details.
  17.  
  18. You should have received a copy of the GNU Library General Public
  19. License along with this library; if not, write to the Free
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.  
  22. Erik Yuzwa
  23. peon AT wazooinc DOT com
  24. */
  25.  
  26.  
  27. #include "peonstdafx.h"
  28.  
  29. namespace peon
  30. {
  31.     /**
  32.     * This object as a way to properly control animation and other effects in our
  33.     * scene relying on the "timing" in the game. Every frame of the game, we 
  34.     * update this object with a snapshot of the current clock of the CPU in order
  35.     * to create a delta (differential) with the last clock snapshot. This delta
  36.     * controls the movement of the objects in our gameworld.
  37.     *
  38.     * To make this object more platform independent, feel free to investigate
  39.     * using the SDL timer functions
  40.     *
  41.     * Note that on some newer multi-processor systems, the QPC doesn't always
  42.     * cut the mustard. Depending upon your app, the resolution of timeGetTime() 
  43.     * might be enough for your object animation...
  44.     *
  45.     * It really just takes some experimentation folks..
  46.     */
  47.     class PEONMAIN_API Timer
  48.     {
  49.     protected:
  50.         /** are we using the high performance timer?*/
  51.         bool m_bUsingQPF;
  52.  
  53.         /** is the timer stopped? */
  54.         bool m_bTimerStopped;
  55.  
  56.         /** LONGLONG for ticks/sec */
  57.         LONGLONG m_llQPFTicksPerSec;
  58.  
  59.         LONGLONG m_llStopTime;
  60.         LONGLONG m_llLastElapsedTime;
  61.         LONGLONG m_llBaseTime;
  62.  
  63.     public:
  64.         /**
  65.         * Constructor
  66.         */
  67.         Timer();
  68.  
  69.         /**
  70.         * Destructor
  71.         */
  72.         ~Timer();
  73.  
  74.         /**
  75.         * This method resets the timer
  76.         */
  77.         void reset();
  78.  
  79.         /**
  80.         * This method starts the timer
  81.         */
  82.         void start();
  83.  
  84.         /**
  85.         * This method is used to stop/pause the timer
  86.         */
  87.         void stop();
  88.  
  89.         /**
  90.         * This method is used to incrementally advance the
  91.         * timer by 0.1 seconds
  92.         */
  93.         void advance();
  94.         
  95.         /**
  96.         * This method returns the absolute system time
  97.         * @return float - absolute system time
  98.         */
  99.         float getAbsoluteTime();
  100.  
  101.         /**
  102.         * This method returns the current time
  103.         * @return float - the current time
  104.         */
  105.         float getTime();
  106.  
  107.         /**
  108.         * This method returns the time that has elapsed between
  109.         * getElapsedTime
  110.         * @return float - the time delta
  111.         */
  112.         float getElapsedTime();
  113.  
  114.         /**
  115.         * This method just returns if our timer is active or not
  116.         * @return bool - true if timer is stopped
  117.         */
  118.         bool isStopped();
  119.  
  120.     };
  121. }
  122.  
  123. #endif
  124.